package org.cn.hj.org.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.cn.hj.org.dao.DepartmentDao;
import org.cn.hj.org.dto.DepartmentDto;
import org.cn.hj.org.service.IDepartmentService;
import org.cn.hj.org.vo.DepartmentVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService {

    @Resource
    private DepartmentDao departmentDao;

    @Override
    public void remove(Long id) {
        departmentDao.deleteById(id);
    }

    @Override
    public void add(DepartmentDto departmentDto) {
        departmentDao.insert(departmentDto);
    }

    @Override
    public void update(DepartmentDto departmentDto) {
        departmentDao.update(departmentDto);
    }

    @Override
    public PageInfo<DepartmentVo> getPageList(DepartmentDto departmentDto) {
        PageHelper.startPage(departmentDto.getCurrent(), departmentDto.getSize());
        List<DepartmentVo> list = departmentDao.getPageList(departmentDto);
        return new PageInfo<>(list);
    }

    @Override
    public DepartmentVo findOneById(Long id) {
        return departmentDao.getOneById(id);
    }
}
